home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / sc3x00 / semainfo.c < prev   
Text File  |  1996-07-10  |  4KB  |  118 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      semainfo.c                                            ║
  4. //   ║ abstract:    This module shows how to make the GetSemaphoreIn-     ║
  5. //   ║              formation system call using the F2 Shell Interface.   ║
  6. //   ║              Obviously, it requires the NetWare Shell.             ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ╚════════════════════════════════════════════════════════════════════╝
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <conio.h>
  25.  
  26. #include "nwsys.h"
  27.  
  28. //
  29. //  First of all, we define the request and reply structures which are
  30. //  needed for the GetSemaphoreInformation API call.  These structures are
  31. //  layed out according to the System Call documentation.
  32. //
  33.  
  34. struct  {
  35.     WORD    sflen;          // length of the structure.  This is 6 + 'onlen'
  36.     BYTE    sfcode;         // the subfunction code, in our case 53.
  37.     WORD    lastRecordSeen; // length of name (below)
  38.     BYTE    semaphoreNameLength;
  39.     char    semaphoreName[128];
  40. }Request;
  41.  
  42. struct connStruct {
  43.     WORD    connectionNumber;
  44.                 // Connection holding semaphore open
  45.     WORD    taskNumber;     // task number holding semaphore open
  46. };
  47.  
  48. struct  {
  49.     WORD    nextRequestRec; // next record to be requested.
  50.     WORD    openCount;      // total number of times opened
  51.     WORD    value;          // value of semaphore
  52.     BYTE    semaphoreCount; //  number of semaphores in this iteration
  53.     struct  connStruct conn[150];
  54.                 //  Array of connection information
  55. } Reply;
  56.  
  57. int numConnections;
  58. char semaphoreName[128];
  59.  
  60. void processEntries(void);
  61. void displayData(void);
  62. //
  63. //  This routine allocates memory for the data returned for each file.
  64. //  It also makes the GetConnectionOpenFiles call and parses the data
  65. //  for each file.
  66. //
  67. void ProcessEntries(void)
  68. {
  69.     numConnections+=Reply.semaphoreCount;
  70. }
  71.  
  72. //
  73. //  Display the list of open files for the connection.
  74. //
  75. void DisplayData( void )
  76. {
  77.     int i;
  78.  
  79.     clrscr();
  80.     printf("\n\nSemaphore Information For %s  Value: %d\n\n",
  81.                 semaphoreName,Reply.value);
  82.     printf("Conn   Task\n");
  83.     printf("----   ----\n");
  84.     for(i=0;i<numConnections;i++) {
  85.         printf(" %02d ",WordSwap(Reply.conn[i].connectionNumber));
  86.         printf("    %02d\n",WordSwap(Reply.conn[i].taskNumber));
  87.     }
  88. }
  89. //
  90. //  This is the main program.  The purpose is to make the GetBinderyObjectID
  91. //  API call to illustrate making system calls using the F2 interface.
  92. //
  93.  
  94. void main(int argc, char *argv[])
  95. {
  96.     int     cc;
  97.     int     length;
  98.  
  99.     if(argc!=2){printf("usage: SEMAINFO semaphoreName\n");exit(1);}
  100.     strcpy(semaphoreName,argv[1]);
  101.     numConnections=0;
  102.     //
  103.     //  Build the request buffer
  104.     //
  105.     Request.sflen = strlen(semaphoreName) + 6;
  106.     Request.sfcode = 242;                       // subfunction code
  107.     length=strlen(semaphoreName);
  108.     Request.semaphoreNameLength=(BYTE)length;
  109.     memcpy(Request.semaphoreName,semaphoreName,strlen(semaphoreName));
  110.     Request.lastRecordSeen = 0;
  111.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  112.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  113.     if( cc == 0 ) {
  114.         ProcessEntries();
  115.         DisplayData();
  116.     }
  117. }
  118.